var express = require('express');
var router = express.Router();
const SeatsApi = require("../api/seats");

/* GET home page. */

router.get('/', async function (req, res, next) {
    const { page, limit } = req.query;
    const result = await SeatsApi.get({ page, limit });
    res.send(
        {
            "code": 0,
            "msg": "",
            "count": result.total,
            "data": result.rows,
        }
    );
});

router.get('/:_id', async function (req, res, next) {
    const { _id } = req.params;
    const data = await SeatsApi.getOne(_id);
    res.send(data);
});

router.post('/', async function (req, res, next) {
    const seat = req.body;
    const data = await SeatsApi.add(seat);
    res.send(data);
});

router.put('/:_id', async function (req, res, next) {
    const seat = req.body;
    const _id = req.params;
    seat.seatsArr = JSON.parse(seat.seatsArr);
    const data = await SeatsApi.update({ _id }, seat);
    res.send(data);
});

router.delete('/', async function (req, res, next) {
    const t_id = req.body;
    const data = await SeatsApi.delete(t_id);
    res.send(data);
});

module.exports = router;
